package com.ayue.clinet.mqspringboot.consumer.work;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

/**
 *
 *  work 工作模式消费者
 * @author yuelinbo
 * @date 2020/3/25 13:05
 **/
@Component
public class WorkConsumer {

    @RabbitHandler
    @RabbitListener(queues = "work-queue")
    public void workConsume1(@Payload String message, @Headers Map<String, Object> headers, Channel channel) {
        System.out.println("work工作模式模式1：consumer----" + message);
        try {
            channel.basicAck((Long) headers.get(AmqpHeaders.DELIVERY_TAG), true);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @RabbitHandler
    @RabbitListener(queues = "work-queue")
    public void workConsume2(@Payload String message, @Headers Map<String, Object> headers, Channel channel) {
        System.out.println("work工作模式模式2：consumer----" + message);
        try {
            channel.basicAck((Long) headers.get(AmqpHeaders.DELIVERY_TAG), true);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
